home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0168_Icon on the notify area of the taskbar.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  7.0 KB  |  208 lines

  1. unit notify;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   ExtCtrls, StdCtrls, shellApi;
  6. type
  7.   TForm1 = class(TForm)
  8.     Button1: TButton;
  9.     Button2: TButton;
  10.     Button3: TButton;
  11.     Image1: TImage;
  12.     Timer1: TTimer;
  13.     Image2: TImage;
  14.     procedure Button1Click(Sender: TObject);
  15.     procedure Button2Click(Sender: TObject);
  16.     procedure Timer1Timer(Sender: TObject);
  17.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23. var
  24.   Form1: TForm1;
  25.   MyNotifyStruct: TNotifyIconData;
  26. { // Here is the structure info from ShellAPI.pas:
  27.   type
  28.     PNotifyIconDataA = ^TNotifyIconDataA;
  29.     PNotifyIconDataW = ^TNotifyIconDataW;
  30.     PNotifyIconData = PNotifyIconDataA;
  31.     TNotifyIconDataA = record
  32.       cbSize: DWORD;
  33.       Wnd: HWND;
  34.       uID: UINT;
  35.       uFlags: UINT;
  36.       uCallbackMessage: UINT;
  37.       hIcon: HICON;
  38.       szTip: array [0..63] of AnsiChar;
  39.     end;
  40.     TNotifyIconDataW = record
  41.       cbSize: DWORD;
  42.       Wnd: HWND;
  43.       uID: UINT;
  44.       uFlags: UINT;
  45.       uCallbackMessage: UINT;
  46.       hIcon: HICON;
  47.       szTip: array [0..63] of WideChar;
  48.     end;
  49.     TNotifyIconData = TNotifyIconDataA;
  50. }
  51. implementation
  52. {$R *.DFM}
  53. procedure TForm1.Button1Click(Sender: TObject);
  54. begin
  55.   with MyNotifyStruct do begin
  56.     cbSize:= sizeof(MyNotifyStruct);
  57.     Wnd:= form1.handle;
  58.     uID:= 1;
  59.     uFlags:=  NIF_ICON or NIF_TIP;
  60.     hIcon:= Image1.picture.icon.handle;
  61.     szTip:= 'Hello Lloyd';
  62.   end;
  63.   Shell_NotifyIcon(NIM_ADD, @MyNotifyStruct);
  64. end;
  65. procedure TForm1.Button2Click(Sender: TObject);
  66. begin
  67.   Shell_NotifyIcon(NIM_Delete, @MyNotifyStruct);
  68. end;
  69. procedure TForm1.Timer1Timer(Sender: TObject);
  70. begin
  71.   StrPCopy(MyNotifyStruct.szTip,TimetoStr(Time));
  72.   if (MyNotifyStruct.hIcon = image1.picture.icon.handle) then
  73.      MyNotifyStruct.hIcon:= image2.picture.icon.handle
  74.   else
  75.      MyNotifyStruct.hIcon:= image1.picture.icon.handle;
  76.  
  77.   Shell_NotifyIcon(NIM_Modify, @MyNotifyStruct);
  78. end;
  79. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  80. begin
  81.   Shell_NotifyIcon(NIM_Delete, @MyNotifyStruct); // clean up
  82. end;
  83. end.
  84.  
  85. { DFM file }
  86. object Form1: TForm1
  87.   Left = 331
  88.   Top = 141
  89.   Width = 435
  90.   Height = 300
  91.   Caption = 'Form1'
  92.   Font.Color = clWindowText
  93.   Font.Height = -11
  94.   Font.Name = 'MS Sans Serif'
  95.   Font.Style = []
  96.   OnClose = FormClose
  97.   PixelsPerInch = 96
  98.   TextHeight = 13
  99.   object Image1: TImage
  100.     Left = 249
  101.     Top = 39
  102.     Width = 34
  103.     Height = 31
  104.     Picture.Data = {
  105.       055449636F6E0000010001002020100000000000E80200001600000028000000
  106.       2000000040000000010004000000000080020000000000000000000000000000
  107.       0000000000000000000080000080000000808000800000008000800080800000
  108.       80808000C0C0C0000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000
  109.       FFFFFF00999999999999999999999999999999999FFFFFFFFFFFFF8888888888
  110.       8FFFFFF997FFFFFFFFFF888888888888888FFFF9977FFFFFFFF8444C44488888
  111.       8888FFF99777FFFFFF4444444444488888888FF997777FFF44444C4C4C4C4C48
  112.       888888F9977777F44444443444444444888888F99777774C444C433C4C4C4C4C
  113.       48888889977774444444C334C444C444C48888899777744C4C4C433C4C4C4C4C
  114.       4C8888899777444444C43334CCC4C4C4C44888899777444C4C43333C4C4C4C4C
  115.       4C38888997744444C4433333CCCCC4CCC433888997744C4C4C4333333C4C4C4C
  116.       4C33888997744444C43333333CCCCCCCC43388899774444C4C333333CC4CCC4C
  117.       4C33888997744444C433333CCCCCCCC33333888997744C4C4C334C4C4CCCCCC3
  118.       33338889977444444433CCCC3CCCCCC3333388F99777444C4C433C433C4CCC4C
  119.       333888F997774444343333333CCCCCCCC4C88FF99777744C333333333C4C4C43
  120.       3C88FFF997777444333333333CCCCCC3348FFFF99777774C333333333C4C3C43
  121.       3FFFFFF997777774333333C333CC3433FFFFFFF9977777774333334C333C4C37
  122.       7FFFFFF9977777777744433444C4477777FFFFF99777777777774C4C4C477777
  123.       777FFFF99777777777777777777777777777FFF9977777777777777777777777
  124.       77777FF9977777777777777777777777777777F9999999999999999999999999
  125.       9999999900000000000000000000000000000000000000000000000000000000
  126.       0000000000000000000000000000000000000000000000000000000000000000
  127.       0000000000000000000000000000000000000000000000000000000000000000
  128.       0000000000000000000000000000000000000000000000000000000000000000
  129.       00000000}
  130.     Visible = False
  131.   end
  132.   object Image2: TImage
  133.     Left = 249
  134.     Top = 81
  135.     Width = 34
  136.     Height = 37
  137.     Picture.Data = {
  138.       055449636F6E0000010001002020100000000000E80200001600000028000000
  139.       2000000040000000010004000000000080020000000000000000000000000000
  140.       0000000000000000000080000080000000808000800000008000800080800000
  141.       80808000C0C0C0000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000
  142.       FFFFFF0000000000000000000000000000000000000000000000000000000000
  143.       0000000000000000000000000000000000000000000000000000000000000000
  144.       0000000000000000000000000330000000000000000000000033303303303300
  145.       0000000000000003303330333003003300000000000000033003330330002333
  146.       0000000000000030000033003033333000000000000033333330000003330003
  147.       33000000080333333333333333300233330000000F033333333333333302333B
  148.       B03000004F8333333333333333333BB003BB00004FF3333333333333B33BB003
  149.       3BBB00004FF333333333B3BB3BB0033BBBB000004FF83B333B3B3B3BBBB03BBB
  150.       BB0300F04FFF33B3B3B3BBBBBBBBBBBB00330FF04FFF8B3B3333BBBBBBBBBB00
  151.       33330FF044FFF8BBB03033BBBBB330333330FFF444FFF8BB0BB3003B33000333
  152.       3330FF44444FF88B3BBB300000033333B33FFF44444FFF3BB0BBB3000333B33B
  153.       B38FF4444444FF003B0BB333333BBBBBB3FFF44444444FF00030BBBBBBBBBBBB
  154.       BBFF444444440000000303BBB3300000BFF44444440000000000000000000000
  155.       0FF4444400000000000000000000000000444444000000000000000000000000
  156.       0000444400000000000000000000000000000444000000000000000000000000
  157.       0000000400000000000000000000000000000000000000000000000000000000
  158.       00000000FFFFFFFFFFFFFFFFFFFF1FFFFF8003FFFC0000FFF800007FF800007F
  159.       E000003F0000001F0000001F0000000F00000007000000070000000000000000
  160.       0000000000000000000000000000000000000000000000000000000000000000
  161.       0000000000C000000FE01F003FFFFF80FFFFFFC0FFFFFFF0FFFFFFF8FFFFFFFE
  162.       FFFFFFFF}
  163.     Visible = False
  164.   end
  165.   object Button1: TButton
  166.     Left = 15
  167.     Top = 36
  168.     Width = 124
  169.     Height = 34
  170.     Caption = 'Add Icon To TaskBar'
  171.     TabOrder = 0
  172.     OnClick = Button1Click
  173.   end
  174.   object Button2: TButton
  175.     Left = 12
  176.     Top = 96
  177.     Width = 127
  178.     Height = 34
  179.     Caption = 'Delete Icon from TaskBar'
  180.     TabOrder = 1
  181.     OnClick = Button2Click
  182.   end
  183.   object Button3: TButton
  184.     Left = 12
  185.     Top = 159
  186.     Width = 130
  187.     Height = 31
  188.     Caption = 'ModifyIcon on TaskBar'
  189.     TabOrder = 2
  190.   end
  191.   object Timer1: TTimer
  192.     Interval = 500
  193.     OnTimer = Timer1Timer
  194.     Left = 375
  195.     Top = 21
  196.   end
  197. end
  198. { DPR file }
  199. program taskbar;
  200. uses
  201.   Forms,
  202.   notify in 'notify.pas' {Form1};
  203. {$R *.RES}
  204. begin
  205.   Application.CreateForm(TForm1, Form1);
  206.   Application.Run;
  207. end.
  208.